<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<%@ include file="../../share/layoutForm.jsp"%> 
	</head>
<body>
<form id="form1">
<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">公司名称<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="organizeName" type="text" onblur="$.ExistField(this.id,'<%=basePath%>sysOrganize/isExist.do')" class="form-control" />
            </td>
            <th class="formTitle">简称</th>
            <td class="formValue">
                <input id="shortName" type="text" onblur="$.ExistField(this.id,'<%=basePath%>sysOrganize/isExist.do')" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">上级公司</th>
            <td class="formValue">
                <div id="parentId" type="selectTree" class="ui-select">
                </div>
            </td>
            <th class="formTitle">排序码</th>
            <td class="formValue">
                <input id="sortCode" type="text" class="form-control" value="1" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">联系电话</th>
            <td class="formValue">
                <input id="organizeTelphone" type="text" class="form-control" />
            </td>
			<th class="formTitle">电子邮箱</th>
            <td class="formValue">
                <input id="organizeEmail" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">传真</th>
            <td class="formValue">
                <input id="organizeFax" type="text" class="form-control" />
            </td>
			<th class="formTitle">负责人</th>
            <td class="formValue">
				<input id="managerId" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">公司地点</th>
            <td class="formValue" colspan="3">
                <div style="float: left; width: 255px;">
                    <div id="provinceId" type="select" class="ui-select" style="float: left; width: 84px; margin-right: 1px;"></div>
                    <div id="cityId" type="select" class="ui-select" style="float: left; width: 84px; margin-right: 1px;"></div>
                    <div id="countyId" type="select" class="ui-select" style="float: left; width: 84px; margin-right: 1px;"></div>
                </div>
                <div style="margin: 0 auto; width: 100%;">
                    <input id="organizeAddress" type="text" class="form-control" style="float: left; width: 355px;" />
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">备注
            </th>
            <td class="formValue" colspan="3">
                <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>
</form>
<script>
    var keyValue = request('keyValue');
    var parentId = request('parentId');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //上级公司
        $("#parentId").ComboBoxTree({
            url: "<%=basePath%>sysOrganize/treeJson.do",
            description: "==最顶级==",
            height: "260px",
            allowSearch: true
        });

        //省份
        $("#provinceId").ComboBox({
            url: "<%=basePath%>sysArea/treeJson.do",
            param: { value: "0" },
            id: "id",
            text: "text",
            description: "选择省",
            height: "170px"
        }).bind("change", function () {
            var value = $(this).attr('data-value');
            $("#cityId").ComboBox({
                url: "<%=basePath%>sysArea/treeJson.do",
                param: { value: value },
                id: "id",
                text: "text",
                description: "选择市",
                height: "170px"
            });
        });
        //城市
        $("#cityId").ComboBox({
            description: "选择市",
            height: "170px"
        }).bind("change", function () {
            var value = $(this).attr('data-value');
            if (value) {
                $("#countyId").ComboBox({
                    url: "<%=basePath%>sysArea/treeJson.do",
                    param: { value: value },
                    id: "id",
                    text: "text",
                    description: "选择县/区",
                    height: "170px"
                });
            }
        });
        //县/区
        $("#countyId").ComboBox({
            description: "选择县/区",
            height: "170px"
        });
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "<%=basePath%>sysOrganize/get.do",
                param: { keyValue: keyValue },
                success: function (data) {
					if(data.type=="0"){
						$("#form1").SetWebControls(data.rows);
						$("#provinceId").trigger("change");
						if(data.rows.cityId){
							$("#cityId").ComboBoxSetValue(data.rows.cityId).trigger("change");
						}
						$("#countyId").ComboBoxSetValue(data.rows.countyId);
					}
                }
            });
        } else {
            $("#parentId").ComboBoxTreeSetValue(parentId);
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["manager"] = $("#managerId").attr('data-text');
        if (postData["parentId"] == "") {
            postData["parentId"] = 0;
        }
        $.SaveForm({
            url: "<%=basePath%>sysOrganize/save.do?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
</body>
</html>